home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Include / FWDrCmd.h < prev    next >
Encoding:
Text File  |  1995-11-08  |  7.5 KB  |  242 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWDrCmd.h
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9. //    This file contains two command classes that handle Drag-and-Drop.
  10. //    These commands must be subclassed to add Undo support for the following actions:
  11. //        drag-move within a part            FW_CDropCommand
  12. //        drag-move to a different part    FW_CDropCommand and FW_CDragCommand
  13. //        drag-copy                        FW_CDropCommand
  14. //========================================================================================
  15.  
  16. #ifndef FWDRCMD_H
  17. #define FWDRCMD_H
  18.  
  19. #ifndef FWCMD_H
  20. #include "FWCmd.h"
  21. #endif
  22.  
  23. #ifndef FWPOINT_H
  24. #include "FWPoint.h"
  25. #endif
  26.  
  27. #ifndef FWREGION_H
  28. #include "FWRegion.h"
  29. #endif
  30.  
  31. // ----- OpenDoc Includes -----
  32.  
  33. #ifndef _ODTYPES_
  34. #include <ODTypes.h>
  35. #endif
  36.  
  37. #ifndef SOM_ODDraft_xh
  38. #include <Draft.xh>
  39. #endif
  40.  
  41. #if FW_LIB_EXPORT_PRAGMAS
  42. #pragma lib_export on
  43. #endif
  44.  
  45. //==============================================================================
  46. //    Constants
  47. //==============================================================================
  48.  
  49. const ODCommandID FW_kDragCommand = 101;    // MEB what should these be?
  50. const ODCommandID FW_kDropCommand = 102;
  51.  
  52. //==============================================================================
  53. //    Forward Declarations
  54. //==============================================================================
  55.  
  56. class FW_CLASS_ATTR FW_CPart;
  57. class FW_CLASS_ATTR FW_CFrame;
  58. class FW_CLASS_ATTR FW_CSelection;
  59. class FW_CLASS_ATTR ODFacet;
  60. class FW_CLASS_ATTR FW_CMouseEvent;
  61. class FW_CLASS_ATTR ODDragItemIterator;
  62. class FW_CLASS_ATTR ODDragAndDrop;
  63.  
  64. //==============================================================================
  65. // FW_CDragCommand - handles the source side of drag-and-drop
  66. //==============================================================================
  67.  
  68. class FW_CLASS_ATTR FW_CDragCommand : public FW_CCommand
  69. {
  70.   public:
  71.     FW_DECLARE_CLASS
  72.  
  73.   public:
  74.     FW_CDragCommand(Environment* ev,
  75.                     FW_CFrame* frame,
  76.                     FW_Boolean canUndo);
  77.  
  78.     virtual ~ FW_CDragCommand();
  79.  
  80. //----------------------------------------------------------------------------------------
  81. //    Inherited API (From FW_CCommand)
  82. //
  83.     virtual void DoIt(Environment* ev);    // Override
  84.         // Don't override. 
  85.         // To make drag-move to another part Undo-able, override these methods:
  86.         //    UndoIt, RedoIt, SaveUndoState, DoClear
  87.  
  88.     virtual void CommitDone(Environment* ev);
  89.         // Called just before the command is deleted.
  90.         // doneState values are kODDone or kODRedone (ODTypes.h)
  91.         // Default calls FreeUndoState if it's a drag-move to another part
  92.  
  93. //----------------------------------------------------------------------------------------
  94. //    New API
  95. //
  96.   public:
  97.     void BeginDrag(Environment* ev, const FW_CMouseEvent& theMouseEvent);
  98.         // Called by frame's Drag method
  99.  
  100.     FW_Boolean IsDragMoveToAnotherPart(Environment* ev);
  101.         // return TRUE if this was a drag-move to another part.
  102.  
  103.   protected:
  104.  
  105.     virtual ODShape* CreateDragShape(Environment* ev, ODFacet* facet);
  106.  
  107.     void AdjustUndo(Environment* ev);
  108.         // Check the drag result, and cancel Undo if the drag was unsuccessful.
  109.  
  110.     void DragCompleted(Environment* ev);
  111.  
  112.     void AbortTransaction(Environment* ev);
  113.         // Clean up the Undo stack if the Drag&Drop operation failed
  114.  
  115. //----------------------------------------------------------------------------------------
  116. //    Data Members
  117. //
  118.   protected:
  119.     ODDropResult    fDragResult;
  120.  
  121.   private:
  122.     ODRgnHandle        fDragRegion;
  123.     ODPart*            fDestPart;            // part in which selected data was dropped
  124.     FW_Boolean        fBeganTransaction;    // remember that we added an ODBeginAction
  125. };
  126.  
  127. //==============================================================================
  128. // FW_CDropCommand - handles the destination side of drag-and-drop
  129. //==============================================================================
  130.  
  131. class FW_CLASS_ATTR FW_CDropCommand : public FW_CCommand
  132. {
  133.   public:
  134.     FW_DECLARE_CLASS
  135.  
  136.   public:
  137.     FW_CDropCommand(Environment* ev,
  138.                     FW_CPart* itsPart,
  139.                     FW_CFrame* frame,
  140.                     ODDragItemIterator* dropInfo, 
  141.                     ODFacet* facet, 
  142.                     const FW_CPoint& dropPoint,
  143.                     FW_Boolean canUndo);
  144.  
  145.     virtual ~ FW_CDropCommand();
  146.  
  147. //----------------------------------------------------------------------------------------
  148. //    Inherited API (From FW_CCommand)
  149. //
  150.     virtual void DoIt(Environment* ev);    // Override
  151.         // Don't override. 
  152.         // To make this command Undo-able, override these methods:
  153.         //    UndoIt, RedoIt, SaveRedoState, DoDrop, DoDroppedInSameFrame
  154.  
  155.     virtual void CommitUndone(Environment* ev);
  156.         // Called just before the command is deleted.
  157.         // doneState value is kODUndone (ODTypes.h)
  158.         // Default calls FreeRedoState if it's not a drag-move within the frame
  159.  
  160. //----------------------------------------------------------------------------------------
  161. //    New API
  162. //
  163.   public:
  164.     ODDropResult         GetDropResult(Environment* ev) const;
  165.     
  166.   protected:
  167.  
  168.     virtual FW_Boolean     DoDrop(Environment* ev, 
  169.                             ODStorageUnit* dropSU, 
  170.                             const FW_CPoint& mouseOffset, 
  171.                             const FW_CPoint& dropPoint,
  172.                             FW_Boolean isDropMove);
  173.     virtual FW_Boolean     DoDroppedInSameFrame(Environment* ev, 
  174.                             ODStorageUnit* dropSU, 
  175.                             const FW_CPoint& originPoint, 
  176.                             const FW_CPoint& dropPoint);
  177.  
  178.     void                 AdjustUndo(Environment* ev);
  179.                             // Check the drop result, and cancel Undo if the drop failed.
  180.  
  181.     void                 GetDropOrigin(Environment* ev, FW_CPoint& originPoint);
  182.                             // Return non-zero value if the source part was moved;
  183.  
  184.     ODDropResult         HandleDrop(Environment* ev);
  185.  
  186.     FW_Boolean            IsDragMoveInSameFrame(Environment* ev) const;
  187.     ODFacet*            GetDropFacet(Environment* ev) const;
  188.  
  189.     //----- Linking/PasteAs -----
  190.     FW_Boolean            HandlePasteAsDialog(Environment* ev, ODStorageUnit* dropSU, FW_Boolean& handledDrop, FW_Boolean& createdLink);
  191.     virtual void        DoDroppedPasteAs(Environment* ev, const FW_CPoint& originPoint, const FW_CPoint& dropPoint);
  192.  
  193.     virtual FW_Boolean    DoPasteAsEmbed(Environment* ev, ODStorageUnit* storageUnit);
  194.                         // Override to PasteAs an embedded part.
  195.  
  196. //----------------------------------------------------------------------------------------
  197. //    Data Members
  198. //
  199.   protected:
  200.     ODDropResult            fDropResult;
  201.  
  202.   private:
  203.     FW_Boolean                fDroppedInSameFrame;
  204.     ODFacet*                fFacet;
  205.     ODDragItemIterator*        fDropItemIterator;
  206.     FW_CPoint                fDropPoint;            // In content coordinates
  207. };
  208.  
  209. //==============================================================================
  210. // FW_CDropCommand inlines
  211. //==============================================================================
  212.  
  213. //--------------------------------------------------------------------
  214. // FW_CDropCommand::GetDropFacet
  215. //--------------------------------------------------------------------
  216. inline ODFacet* FW_CDropCommand::GetDropFacet(Environment* ev) const
  217. {
  218.     return fFacet;
  219. }
  220.  
  221. //--------------------------------------------------------------------
  222. // FW_CDropCommand::GetDropResult
  223. //--------------------------------------------------------------------
  224. inline ODDropResult FW_CDropCommand::GetDropResult(Environment* ev) const
  225. {
  226.     return fDropResult;
  227. }
  228.  
  229. //--------------------------------------------------------------------
  230. // FW_CDropCommand::IsDragMoveInSameFrame
  231. //--------------------------------------------------------------------
  232. inline FW_Boolean FW_CDropCommand::IsDragMoveInSameFrame(Environment* ev) const
  233. {
  234.     return (fDroppedInSameFrame && fDropResult == kODDropMove);
  235. }
  236.  
  237. #if FW_LIB_EXPORT_PRAGMAS
  238. #pragma lib_export off
  239. #endif
  240.  
  241. #endif
  242.